﻿#include "OperPhysicsPropFE.h"
#include "GUIDialog/GUIPhyscisDialog/PhysicsDialogFEProperty.h"
#include "updateBrowserTable.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsFEModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractSection.h"

namespace ModelOper
{
    bool ModelOper::OperPhysicsPropFE::execGUI()
    {
        //菜单栏按钮点击事件触发
        if (_emitter == nullptr) return false;
        const QString name = _emitter->objectName();
        if (name == "actionFEProperty")
            createPhysicsProp();
        return false;
    }

    bool OperPhysicsPropFE::execProfession()
    {
        return false;
    }

    void OperPhysicsPropFE::createPhysicsProp()
    {
        //弹出对话框
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        GUI::PhysicsDialogFEProperty dlg(GUI::PhysicsDlgExecType::Create, -1, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropFE::duplicatePhysicsProp(const int propID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::PhysicsDialogFEProperty dlg(GUI::PhysicsDlgExecType::Duplicate, propID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropFE::editPhysicsProp(const int propID)
    {
        QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
        //编辑对话框
        GUI::PhysicsDialogFEProperty dlg(GUI::PhysicsDlgExecType::Edit, propID, mw);
        //更新列表
        if (QDialog::Accepted == dlg.exec())
            ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropFE::removePhysicsProp(const int propID)
    {
        Acoustics::FITKAcousticsDiscModel* disc = Acoustics::FITKAcousticsDiscModel::GetDiscModelFromFrame();
        if (!disc)return;
        Acoustics::FITKAcousticsFEModel* feModel = disc->getFEModel();
        if (!feModel) return;

        //获取FE属性管理器
        Interface::FITKAbstractSectionManager *feMgr = feModel->getSectionManager();
        if (feMgr == nullptr) return;

        //移除并更新列表
        feMgr->removeDataByID(propID);
        ModelOper::updateBrowserTable();
    }

    void OperPhysicsPropFE::setAttribute(const QString & name, const QString & text, const int attrIndex, const QList<int>& propID)
    {
    }
}